<?php
#============================
#	Filename: chainlist.qgmod.php
#	Note	: 关联信息
#	Version : 2.0
#	Author  : ovsexia
#	Update  : 2018-06-24
#============================
global $FS,$DB,$PA,$prefix,$bi;
$md5 = md5(LANGUAGE_ID."_".$proID."_".$limit);
$cache_file = "data/cache/chainlist_".$md5.".php";#[缓存文件]
$check_status = false;
if($iscache)
{
	$check_status = CheckCache($cache_file);#[判断缓存文件的存储状态]
}
if($check_status)
{
	include_once($cache_file);
	unset($cache_file);
	return $list;
}

$sql = "SELECT chainid FROM ".$prefix."msg WHERE id='".$proID."' ";
$rs = $DB->qgGetOne($sql);

if(!$rs["chainid"])
{
	return false;
}
$chain_arr = explode(",",$rs["chainid"]);
foreach($chain_arr AS $key=>$value)
{
	$rsc = $DB->qgGetOne("SELECT * FROM ".$prefix."msg WHERE ifcheck='1' AND id='".$value."'");
	if($rsc)
	{
		$msglist[] = $rsc;
	}
}
#[读取数量]
$chain_num = count($msglist);
if($chain_num > $limit)
{
	for($i=0;$i<$limit;$i++)
	{
		$rslist[$i] = $msglist[$i];
	}
}
else
{
	$rslist = $msglist;
}

$i = 1;
foreach($rslist AS $key=>$value)
{
	$value["subject"] = $value["subject".$bi];
	
	$sql = "SELECT * FROM ".$prefix."upfiles where id =".$value["thumb"];
	$rs = $DB->qgGetOne($sql);
	$value["folder"] = $rs["folder"];
	$value["filename"] = $rs["filename"];
	$value["markfile"] = $rs["markfile"];
	$value["thumbfile"] = $rs["thumbfile"];
	
	$sql = "SELECT * FROM ".$prefix."msg_content where id =".$value["id"];
	$rs = $DB->qgGetOne($sql);
	$value["content"] = $rs["content".$bi];
	$value["cut_content"] = strip_tags($value["content"]);
	
	#[获取自定义字段]
	$value["fieldlist"] = $PA->fieldlist($value["id"]);
	if($value["fieldlist"])
	{
		foreach($value["fieldlist"] AS $key2=>$value2)
		{
			$value[$value2["sign"]] = $value2["field_content"];
		}
	}
	
	#[日期转换]
	$value["year"] = date("Y",$value["postdate"]);
	$value["day"] = date("d",$value["postdate"]);
	$value["month"] = monthc(date("m",$value["postdate"]),"min"); //[min] or [ful]

	//首项尾项
	if($i==1)
	{
		$value["first"] = true;
	}
	if($i==count($rslist))
	{
		$value["last"] = true;
	}
	$value["row_index"] = $i;
	$i ++;
	$additionlist[] = $value;	
}
unset($sql);
if(!$additionlist)
{
	return false;
}
$list = _____QGMODULE_CLEARUP_LIST($additionlist,0,true);
$FS->qgWrite($list,$cache_file,"list");
unset($additionlist,$cache_file);
return $list;
?>